package com.bbbk.util.word.conf;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.tomcat.jni.File;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;

public class Result<T> {
	
	public static final int CODE_SUCCESS = 0;
	
	public static final int CODE_FAILURE = -500;

	/**
	 * 200 成功 ，其他都失败
	 */
	protected Integer resultStatus = Result.CODE_SUCCESS;
	
	protected String msg = "成功";
	
	protected T data;
	

	
	public boolean hasSuccess(){
		return this.getResultStatus()==CODE_SUCCESS;
	}
	
	public static <T> Result<T> success(T result) {
		Result<T> result2 = new Result<T>();
		result2.setData(result);
		return result2;
	}

	public static <T> Result<T> failure(String errorMsg) {
		Result<T> result2 = new Result<T>();
		if (StrUtil.isBlank(errorMsg)) {
			result2.setMsg("失败");
		} else {
			result2.setMsg(errorMsg);
		}
		result2.setResultStatus(Result.CODE_FAILURE);
		return result2;
	}
//	/**
//	 * tj
//	 * 2018年11月15日 上午9:37:41
//	 * @param result 返回数据
//	 * 成功
//	 */
//	public  Result<T> success(T result) {
//		Result<T> result2 = new Result<T>();
//		result2.setData(result);
//		return result2;
//	}
//	
//	/**
//	 * 失败
//	 * tj
//	 * @param errorMsg 错误描述
//	 * @return
//	 * 2018年11月15日 上午9:44:38
//	 */
//	public  Result<T> failure(String errorMsg) {
//		Result<T> result2 = new Result<T>();
//		result2.setMsg(errorMsg);
//		result2.setResultStatus(Result.CODE_FAILURE);
//		return result2;
//	}



	public Integer getResultStatus() {
		return resultStatus;
	}

	public void setResultStatus(Integer resultStatus) {
		this.resultStatus = resultStatus;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "Result{" +
				"resultStatus=" + resultStatus +
				", msg='" + msg + '\'' +
				", data=" + data +
				'}';
	}
	public static void main(String[] args) throws IOException {
		Map<String, Object> formMap = new HashMap<>();
		formMap.put("id", "69c72f78dee14f72b42137db7e8c2232");
		formMap.put("jsonDataStr", "{\r\n" + 
				"				    \"aaa\":\"aaa1\",\r\n" + 
				"				    \"arr\":[\r\n" + 
				"				        {\r\n" + 
				"				            \"hh\":\"hhhhh22222\",\r\n" + 
				"				            \"h\":\"hhhhhhhhh\"\r\n" + 
				"				        },\r\n" + 
				"				        {\r\n" + 
				"				            \"hh\":\"hhhhh22222\",\r\n" + 
				"				            \"h\":\"hhhhhhhhh\"\r\n" + 
				"				        },\r\n" + 
				"				        {\r\n" + 
				"				            \"hh\":\"hhhhh22222\",\r\n" + 
				"				            \"h\":\"hhhhhhhhh\"\r\n" + 
				"				        }\r\n" + 
				"				    ],\r\n" + 
				"				    \"ccc\":\"ccc\",\r\n" + 
				"				    \"bbb\":\"bbb2\"\r\n" + 
				"				}\r\n" + 
				"	");
		java.io.File file1 = new java.io.File("3.pdf");
		boolean createNewFile = file1.createNewFile();
		InputStream bodyStream = HttpUtil.createPost("http://127.0.0.1:8999/builderPdf").form(formMap).execute().bodyStream();
		
		 HttpUtil.createPost("http://127.0.0.1:8999/builderPdf").form(formMap).execute().writeBody(file1);
		 System.out.println(bodyStream);
		 
		
	}
}
